package com.ruoyi.project.baoxiu.moban.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.baoxiu.moban.domain.WarrantyCard;
import com.ruoyi.project.baoxiu.moban.service.IWarrantyCardService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 保修卡模板Controller
 * 
 * @author wyh
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/baoxiu/moban")
public class WarrantyCardController extends BaseController
{
    @Autowired
    private IWarrantyCardService warrantyCardService;

    /**
     * 查询保修卡模板列表
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarrantyCard warrantyCard)
    {
        startPage();
        List<WarrantyCard> list = warrantyCardService.selectWarrantyCardList(warrantyCard);
        return getDataTable(list);
    }

    /**
     * 导出保修卡模板列表
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:export')")
    @Log(title = "保修卡模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarrantyCard warrantyCard)
    {
        List<WarrantyCard> list = warrantyCardService.selectWarrantyCardList(warrantyCard);
        ExcelUtil<WarrantyCard> util = new ExcelUtil<WarrantyCard>(WarrantyCard.class);
        util.exportExcel(response, list, "保修卡模板数据");
    }

    /**
     * 获取保修卡模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(warrantyCardService.selectWarrantyCardById(id));
    }

    /**
     * 新增保修卡模板
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:add')")
    @Log(title = "保修卡模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarrantyCard warrantyCard)
    {
        return toAjax(warrantyCardService.insertWarrantyCard(warrantyCard));
    }

    /**
     * 修改保修卡模板
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:edit')")
    @Log(title = "保修卡模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarrantyCard warrantyCard)
    {
        return toAjax(warrantyCardService.updateWarrantyCard(warrantyCard));
    }

    /**
     * 删除保修卡模板
     */
    @PreAuthorize("@ss.hasPermi('baoxiu:moban:remove')")
    @Log(title = "保修卡模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warrantyCardService.deleteWarrantyCardByIds(ids));
    }
}
